package assign4;

import java.rmi.*;

/** The remote interface to a distributed database
 */
public interface IRemoteDatabase extends Remote
{
	/** Performs a read operation on a given table, this locks the 
	 * table globally in order to maintain coherent reads.
	 */
	public int read(int table) throws RemoteException;
	
	/** Performs a write operation on a given table, locks the
	 * table globally in order to maintain coherence throughout the
	 * distributed database.
	 */
	public void write(int val, int table) throws RemoteException;
	
	/** Called by the master server on it's clients in order to update
	 * them with new values.
	 */
	public void remoteWrite(int dataToWrite, int table) throws RemoteException;
	
	/** Registers a slave server with the master server so that it can be manipulated
	 * by it in the future. This allows the master server to run RPCs on the slaves.
	 */
	public boolean registerSlave(String slaveServerUri) throws RemoteException;
	
	/** Acquires a write lock for a given table, should only be called on the
	 * master server, a single write operation can occur on a given table at once.
	 */
	public void startWrite(int table) throws RemoteException;
	
	/** Releases a write lock for a given table, should only be called on the 
	 * master server
	 */
	public void endWrite(int table) throws RemoteException;
	
	/** Waits for a read lock for a given table, should only be called on the 
	 * master server, multiple reads can occur on the same table at once.
	 */
	public void startRead(int table) throws RemoteException;
	
	/** Releases a read lock for a given table, should only be called on the 
	 * master server
	 */
	public void endRead(int table) throws RemoteException;
	
	/** Called on the master server to cascade the write operation to all slave
	 * servers. 
	 */
	public void commitWrite(int dataToCommit, int table) throws RemoteException;
}
